package Controller;

import Model.Grid;
import Views.CircleView;
import Views.RectangleView;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;


public class KeyController extends Controller implements KeyListener
{
    
    public KeyController(Grid model, CircleView circleView, RectangleView rectangleView)
    {
        super(model,circleView,rectangleView);
    }    
    
    @Override
    public void keyTyped(KeyEvent ke)
    {
        
    }

    @Override
    public void keyPressed(KeyEvent ke)
    {
         int moveLeft =this.model.getAvatar().getI() - 1;
         int moveRight =this.model.getAvatar().getI() +1;
         int moveUp =this.model.getAvatar().getJ() + 1;
         int moveDown =this.model.getAvatar().getJ() - 1;
           
         
         switch (ke.getKeyCode()) {
                // 37 lefKey 38 upkey...        
                case 37:
                    if (isMoveAuthorized(moveLeft, this.model.getAvatar().getJ())) 
                    {
                        this.model.moveAvatar(moveLeft,this.model.getAvatar().getJ());
                    }
                    break;
                case 38:
                   if (isMoveAuthorized(this.model.getAvatar().getI(),moveDown)) 
                    {
                        this.model.moveAvatar(this.model.getAvatar().getI(),moveDown);
                    }
                    break;
                case 39:
                    if (isMoveAuthorized(moveRight, this.model.getAvatar().getJ())) 
                    {
                        this.model.moveAvatar(moveRight,this.model.getAvatar().getJ());
                    }
                    break;
                case 40:
                    if (isMoveAuthorized(this.model.getAvatar().getI(),moveUp)) 
                    {
                        this.model.moveAvatar(this.model.getAvatar().getI(),moveUp);
                    }
                    break;
            }
    }

    @Override
    public void keyReleased(KeyEvent ke)
    {
       
    }
    
}
